package  
{
	import org.flixel.*;
	import org.flixel.plugin.photonstorm.*;
	import flash.display.StageDisplayState;
	import flash.events.Event;
	
	/**
	 * Contains all GUI elements that are shared across multiple states
	 * Includes additional debugging inputs to allow easier navigation during testing (To be disabled in release)
	 * @author Lachlan McInnes
	 */
	public class ExtendedFlxState extends FlxState
	{
		protected var fullscreenButton:FlxButtonPlus;
		
		public function ExtendedFlxState() 
		{
			FlxG.mouse.show();
			
			fullscreenToggle(StageDisplayState.NORMAL); 
			
			if (FlxG.getPlugin(FlxMouseControl) == null)
			{
				FlxG.addPlugin(new FlxMouseControl);
			}
			
			FlxG.stage.addEventListener(Event.RESIZE, resizeWindow);
		}
		
		/*
		 * Adds standard GUI elements to all screens including:
		 * - Mute music
		 * - Adjust/mute sound
		 * */
		protected function addStandardGUI():void
		{
			if (!fullscreenButton)
			{
				fullscreenButton = new FlxButtonPlus(FlxG.width - 105, 5, fullscreenToggle);
			}
			add(fullscreenButton);
		}
		
		/*
		 * Includes all shared debug commands
		 * */
		override public function update():void 
		{
			super.update();
		}
		
		private function fullscreenToggle(ForceDisplayState:String = null):void
		{
			if (ForceDisplayState) 
			{
				FlxG.stage.displayState = ForceDisplayState;
			} 
			else 
			{
				if (FlxG.stage.displayState == StageDisplayState.NORMAL) 
				{
					FlxG.stage.displayState = StageDisplayState.FULL_SCREEN;
				} 
				else 
				{
					FlxG.stage.displayState = StageDisplayState.NORMAL;
				}
			}
			
			resizeWindow();
		}
		
		protected function resizeWindow(e:Event = null):void
		{
			FlxG.width = FlxG.stage.stageWidth / FlxCamera.defaultZoom;
			FlxG.height = FlxG.stage.stageHeight / FlxCamera.defaultZoom;
			
			FlxG.resetCameras(new FlxCamera(0, 0, FlxG.width, FlxG.height));
			
			//resize screen features here or in overridden function
			//must account for things not being declared yet
			if (fullscreenButton)
			{
				fullscreenButton.x = FlxG.width - 105;
			}
			else
			{
				fullscreenButton = new FlxButtonPlus(FlxG.width - 105, 5, fullscreenToggle);
			}
		}
		
		protected function disableFullscreenButton():void
		{
			fullscreenButton.kill();
		}
		
		protected function enableFullscreenButton():void
		{
			fullscreenButton.revive();
		}
	}
}